import { setUser, getUser, removeUser } from '@/utils/user.js'

export default {
    namespaced: true,
    state: {
        loginStatus: false,//登录状态
        token: null,
        userInfo: {}//用户信息
    },
    getters: {
    },
    mutations: {
        userLogin(state, data) {
            state.loginStatus = true;
            state.token = data.token;
            state.userInfo = data;
            setUser(data)
        },
        userLogOut(state) {
            state.loginStatus = false;
            state.token = null;
            state.userInfo = {};
            removeUser()
        },
        initUser(state) {
            let data = getUser()
            if (data) {
                state.loginStatus = true;
                state.token = data.token;
                state.userInfo = data;
            }
        }
    },
    actions: {
    },
    modules: {
    }
}